package com.macro.mall.service.impl;

import com.macro.mall.dao.UmsAttributeDao;
import com.macro.mall.dto.PmsPortalProductDetail;
import com.macro.mall.mapper.PmsBrandMapper;
import com.macro.mall.mapper.PmsProductMapper;
import com.macro.mall.model.PmsBrand;
import com.macro.mall.model.PmsProduct;
import com.macro.mall.model.PmsProductAttribute;
import com.macro.mall.service.UmsPortalProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：MinxiaoHao
 * @Description:
 * @name：PmsPortalProductService
 * @Date：2024/10/19 19:37
 */
@Service
public class UmsPortalProductServiceImpl implements UmsPortalProductService {
    @Resource
    private PmsProductMapper productMapper;

    @Resource
    private PmsBrandMapper brandMapper;

    @Resource
    private UmsAttributeDao pmsAttributeDao;

    /**
     * 获取前台商品详情
     * @param id
     * @return
     */
    @Override
    public PmsPortalProductDetail detail(Long id) {
        //获取商品详情
        PmsProduct pmsProduct = productMapper.selectByPrimaryKey(id);
        //获取品牌信息
        PmsBrand pmsBrand = brandMapper.selectByPrimaryKey(pmsProduct.getBrandId());
        //获取商品属性信息
        List<PmsProductAttribute> productAttributeList = pmsAttributeDao.selectProductAttr(pmsProduct.getProductAttributeCategoryId());
        PmsPortalProductDetail productDetail = new PmsPortalProductDetail();
        productDetail.setProduct(pmsProduct);
        productDetail.setBrand(pmsBrand);
        productDetail.setProductAttributeList(productAttributeList);
        return productDetail;
    }
}
